package com.shop.service;

import com.shop.entity.MySystemInfo;
import com.shop.model.vo.Rsp;
import com.shop.util.MonitorSystemInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class SystemInfoService {

    public Rsp getSystemInfo() throws Exception {
        MonitorSystemInfo info = new MonitorSystemInfo();
        MySystemInfo mySystemInfo = new MySystemInfo();
        mySystemInfo.setCpuUsageRate(info.getCpuUsageRate());
        mySystemInfo.setMemUsageRate(info.getMemoryUsageRate());
        mySystemInfo.setDiskUsageRate(info.getDiskIoUsageRate());
        mySystemInfo.setDiskUsage(info.getCpuUsageRate());
        mySystemInfo.setIpAddress(info.getDefaultIpAddress());
        mySystemInfo.setMacAddress(info.getMAC());
        mySystemInfo.setDnsAddress(info.getFQDN());
        mySystemInfo.setIoTotalByte(info.getTotalByte());
        MySystemInfo jvmInfo = info.memoryInfo();
        mySystemInfo.setJvmHeadInitMemory(jvmInfo.getJvmHeadInitMemory());
        mySystemInfo.setJvmHeadMaxMemory(jvmInfo.getJvmHeadMaxMemory());
        mySystemInfo.setJvmHeadUsedMemory(jvmInfo.getJvmHeadUsedMemory());
        mySystemInfo.setJvmHeadCommittedMemory(jvmInfo.getJvmHeadCommittedMemory());
        mySystemInfo.setJvmHeadRate(jvmInfo.getJvmHeadRate());
        mySystemInfo.setJvmNonHeapRate(jvmInfo.getJvmNonHeapRate()); //非堆使用率
        return !StringUtils.isEmpty(mySystemInfo) ? Rsp.success(mySystemInfo) : Rsp.fail();
    }


}
